<?
	/* Se asegura que el archivo es incluido por el index */
		defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
	/* Cuando se hace el include del archivo automaticamente crea un objeto y lo guarda en una variable temporal */
		$this->oTmpObject = new Recorrido_atractivo_frm( $this );

	class Recorrido_atractivo_frm extends Frm
	{
	function setValue ( $ncRecorrido, $ncAtractivo, $ncOrden )
		{
			$cSql = "SELECT cDescripcion, cDuracion, nExtension, cUbicacion, nOrden, cReferencia, cTitulo, bBaja
								FROM gtRecorridoAtractivo
								WHERE ncRecorrido = $ncRecorrido
									AND ncAtractivo = $ncAtractivo
									AND ncOrden = $ncOrden";
			$aRow = $this->oDatabase->getArray($cSql);
			$this->setFieldsArray ( $aRow );
			$this->aFields[Parada]->aInput[nOrden]->setValue( $aRow[nOrden] );
			$this->aFields[Parada]->aInput[cReferencia]->setValue( $aRow[cReferencia] );
			return $aRow;
		}
	function setLevel( $nLevel)
		{
			switch ( $nLevel )
			{
				case 2:
					$ncRecorrido = getParam('ncRecorrido');
					$cSql = "SELECT ncCategoriaRecorrido FROM gtRecorrido WHERE ncRecorrido = $ncRecorrido";
					$ncCategoriaRecorrido = $this->oDatabase->getData($cSql);
					switch ( $ncCategoriaRecorrido )
					{
						case 17:
							if ( $this->isRetrievable() && $this->aFields['ncRecorrido']->getValue() && $this->aFields['ncAtractivo']->getValue() && $this->aFields['ncOrden']->getValue() )
								$this->aInput = array( 'ncRecorrido','ncOrden', 'Atractivo', 'cTitulo', 'cDescripcion', 'Parada', 'nExtension',  'bBaja'  );
							else
								$this->aInput = array( 'ncRecorrido','ncOrden', 'ncAtractivo', 'Atractivo', 'cTitulo', 'cDescripcion', 'Parada', 'ncPersona', 'ncRol');
						break;
						case 15:
							if ( $this->isRetrievable() && $this->aFields['ncRecorrido']->getValue() && $this->aFields['ncAtractivo']->getValue() && $this->aFields['ncOrden']->getValue() )
								$this->aInput = array( 'ncRecorrido','ncOrden', 'Atractivo', 'cTitulo', 'cDescripcion', 'bBaja' );
							else
								$this->aInput = array( 'ncRecorrido','ncOrden', 'ncAtractivo', 'Atractivo', 'cTitulo', 'cDescripcion');
						break;
						default:
							$this->aInput = array( 'ncRecorrido','ncOrden','ncAtractivo', 'cTitulo', 'Parada', 'cDescripcion', 'cUbicacion','nExtension','cDuracion', 'bBaja' );
						break;
					}
				break;
			}
		}
	function initializeForm()
		{
			// Configura el Titulo
				$this->setLabel("Atractivo - Recorrido");
			// Crea los subformularios
				$this->aFields['Atractivo']= $this->oModule->loadClass( 'Atractivo_frm' );
			// Si Recibe la Pk => busca los datos
				if ( $this->isRetrievable() && $this->aFields['ncRecorrido']->getValue() && $this->aFields['ncAtractivo']->getValue() && $this->aFields['ncOrden']->getValue() )
				{
					$aRow = $this->setValue( $this->aFields['ncRecorrido']->getValue(), $this->aFields['ncAtractivo']->getValue(), $this->aFields['ncOrden']->getValue() );
					$this->aFields['Atractivo']->setValue( $this->aFields['ncAtractivo']->getValue() );
				}
			return true;
		}
	function Recorrido_atractivo_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
			$this->aFields['ncOrden']		= new Input("Codigo","ncOrden", '', false, true);
			$this->aFields['ncRecorrido']	= new InputList( "Recorrido", "ncRecorrido" );
			$this->aFields['ncAtractivo']	= new InputLookUp( "Atractivo", "ncAtractivo" );
			$this->aFields['cTitulo']		= new InputText( "Titulo", "cTitulo" );
			$this->aFields['Parada']		= new InputArray( "Parada" );
			$this->aFields['cDescripcion']	= new InputText( "Descripcion", "cDescripcion" );
			$this->aFields['cUbicacion']	= new InputText( "Ubicacion", "cUbicacion" );
			$this->aFields['ncUbicacion']	= new InputList( "Ubicacion", "ncUbicacion" );
			$this->aFields['nExtension']	= new InputNumber( "Extension", "nExtension" );
			$this->aFields['cDuracion']		= new InputText( "Duracion", "cDuracion" );
			$this->aFields['bBaja']			= new InputList( "Baja", "bBaja" );
			$this->aFields['ncPersona']		= new InputList( "Personalidad", "ncPersona" );
			$this->aFields['ncRol']		= new InputList( "Rol", "ncRol" );

			$this->aFields['Parada']->addinput( new InputNumber( "Orden", "nOrden" ) ) ;
			$this->aFields['Parada']->addinput( new InputText( "Referencia", "cReferencia" )) ;

			$this->setMultiLanguage();
		}

	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
				case 'Atractivo':
					if ( $this->aFields['ncAtractivo']->getValue() ) 
					{
						$oField->setValue( $this->aFields['ncAtractivo']->getValue() );
						$oField->setFormName( $this->getFormName() );
						$oField->setOptions(DEFAULT_MAKE_INC);
						$oField->setOptionsLevel(3);
					} else 
					{
						$oField->setOptionsLevel(4);
					}
				break;
				case 'ncRecorrido':
					if ( $this->aFields['ncRecorrido']->getValue()  )
					{
						$oField->setHidden();
					} else
					{
						$oField->setWidth(150);
						$cSql = "SELECT ncRecorrido, " .  $this->oDatabase->dbConcat( 'cdRecorrido', " ' ( ' " , 'cdCategoriaRecorrido', " ' ) ' "  )  . " FROM gtRecorrido as Rec LEFT JOIN gcCategoriaRecorrido as CRe ON CRe.ncCategoriaRecorrido = Rec.ncCategoriaRecorrido ORDER BY 2";
						$oField->setMatrix( $this->oDatabase->getMatrix($cSql)  );
						$oField->setForm( $this );
						$oField->addActionArray( 2, $this->oModule->getActionArray( AGREGAR_RECORRIDO), ''  );
						$oField->addActionArray( 3, $this->oModule->getActionArray( MODIFICAR_RECORRIDO), '' );
					}
				break;
				case 'ncPersona':
					$cSql = "SELECT ncPersona, concat(cApellido, ' ', cNombre)  FROM gtPersona order by 2";
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql)  );
					$oField->setForm( $this );
					$oField->addActionArray( 2, $this->oModule->getActionArray( AGREGAR_PERSONA2), ''  );
					$oField->addActionArray( 3, $this->oModule->getActionArray( MODIFICAR_PERSONA2), '' );
					
					break;
				case 'ncRol':
					$cSql = "SELECT ncRol, cdRol FROM gtRolPersona order by 2";
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql)  );
					break;
				case 'ncUbicacion':
					$cSql = "SELECT ncUbicacion, cdUbicacion FROM acUbicacion WHERE ncPais = 8 and ncUbicacionPadre = 25 order by 2";
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql)  );
					break;
				case 'cDuracion':
					if ( $this->getOptionsLevel() == 2 ) $oField->setMultiLanguage();
					break;
				case 'bBaja':
					$oField->setDefault(0);
					$oField->setBool();
				break;
				case 'ncAtractivo':
					$oField->setForm( $this );
					if ( $oField->getValue() )
					{
						$cSql = "SELECT cdAtractivo FROM gtAtractivo WHERE ncAtractivo = " . $oField->getValue();
						$oField->setDescription( extractLanguage( $this->oDatabase->getData( $cSql ), 'es') );
					}
					$oField->addActionArray( 2, $this->oModule->getActionArray( BUSCAR_ATRACTIVO ) );
					$oField->addActionArray( 2, $this->oModule->getActionArray( AGREGAR_ATRACTIVO), 'ncRecorrido=' . $this->aFields['ncRecorrido']->getValue()  );
					$oField->addActionArray( 3, $this->oModule->getActionArray( MODIFICAR_ATRACTIVO ), '' );
					$cUrl = URL_ROOT . '?' . PARAM_REFRESH . '=class&amp;' . PARAM_MODULE . '=git&amp;' . PARAM_ACTION . '=' . BUSCAR_ATRACTIVO . '&amp;' . PARAM_CLASS . '=atractivo_lst&amp;' . PARAM_METHOD . '=getData';
					$oField->setEditable ( $cUrl );
					$oField->setDisabled( $this->aFields['ncAtractivo']->getValue()  ? true:false );
					$oField->setOnChangeAutoSubmit( $this );
				break;
				case 'Parada':
					if(   $this->aFields['ncRecorrido']->getValue() )
					{
						$nNextOrden = $this->oDatabase->nextKey( "gtRecorridoAtractivo", "nOrden", "ncRecorrido = " . $this->aFields['ncRecorrido']->getValue() );
						$oField->aInput[nOrden]->setDefault($nNextOrden);
					}
				break;					
				
				case 'cDescripcion':
					//$oField->setEditor();
					$oField->setLength(4096);
					if ( $this->getOptionsLevel() == 2 ) $oField->setMultiLanguage();
				break;
				case 'cTitulo':
					if ( $this->getOptionsLevel() == 2 ) $oField->setMultiLanguage();
				break;
			}
		}
	}
?>